import { Tool } from "@langchain/core/tools";
import { z } from "zod";
const WeatherInputSchema = z.object({
  location: z.string().describe('中文城市名，如"北京"'),
  unit: z.enum(['celsius', 'fahrenheit']).optional().describe('温度单位，默认celsius（摄氏度）'),
});

// 天气工具
export class WeatherTool extends Tool {
  name = 'getCurrentWeather';
  description = '获取指定城市的当前天气';
  schema = WeatherInputSchema;
  async _call(args: z.infer<typeof WeatherInputSchema>) {
    const { location, unit = 'celsius' } = args; // 解构参数，指定默认值
    // 模拟天气数据（实际场景调用真实API）
    const weatherInfo = {
      location,
      temperature: unit === 'celsius' ? '22' : '72',
      unit,
      forecast: ['晴朗', '微风'],
      humidity: '65%',
    };
    return JSON.stringify(weatherInfo);
  }
}